#coding=utf-8
'''
Created on 2009-11-21

@author: wenjinjin@gmail.com
'''
from google.appengine.ext import db
from mod.tag import Tag
from mod.blog import Blog
class TagMap(db.Model):
    '''
    classdocs
    '''
    tag = db.ReferenceProperty(Tag)
    blog = db.ReferenceProperty(Blog)
    createtime = db.DateTimeProperty(auto_now_add=True)
    
    def addMap(self,tagtxt,blog):
        
        tagtxt = tagtxt.replace("，".decode("utf-8"),",")
        tags =  tagtxt.split(",")
        for tagtxt in tags:
            tag = Tag().getTag(tagtxt)
            if self.notInMap(tag, blog):
                tagmap = TagMap(tag=tag,blog=blog)
                tagmap.put()
    def notInMap(self,tag,blog):
        query = db.GqlQuery("select * from TagMap where tag=:1 and blog = :2",tag,blog)
        tagmap = query.get()
        if tagmap:
            return False
        else:
            return True